<template>
  <div class="recommend">
    <h4 class="title">推荐商品</h4>
    <div class="recommend-main">
      <div class="item"
       v-for="(item, index) in items"
       @click="clickItem(item.id, index)"
      :key="item.id">
        <img v-lazy="item.pic" alt="">
        <p class="name">{{item.name}}</p>
        <div class="action">
          <span class="price">{{item.minPrice | currency}}</span>
          <van-icon @click.stop="addCart(item)" class-prefix="icon" class="iconfont" name="jiaru"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { currency } from 'utils/filters'
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickItem (itemId, index) {
      this.$emit('clickItem', { itemId, index })
    },
    addCart (item) {
      this.$emit('clickAdd', item)
    }
  },
  filters: {
    currency
  }
}
</script>

<style lang="scss" scoped>
.title{
  line-height:50px;
  font-size: 18px;
  margin:0;
  background-color: #f1f1f1;
  color:#333;
  padding-left:10px;
}
.recommend-main{
  display: flex;
  flex-wrap: wrap;
  .item{
    width: 50%;
    box-sizing: border-box;
    padding: 0 10px;

    img{
      width: 80%;
      display: block;
      margin: 0 auto;
    }
    .name{
      font-size: 12px;
      font-weight: bold;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .action{
      color:#f66;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 10px;
    }
  }
}
</style>
